package cn.jinjimi.app.reader.holder;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import cn.jinjimi.base.util.DateUtils;
import cn.jinjimi.app.R;
import cn.jinjimi.app.reader.bean.ArticleViewData;
import cn.jinjimi.app.reader.bean.ShareInfo;
import cn.jinjimi.app.main.widget.CommonRV.BaseHolder;
import cn.jinjimi.app.main.widget.CommonRV.IActionListener;
import cn.jinjimi.app.main.widget.FrescoImageView.FrescoImageView;
import cn.jinjimi.app.main.widget.SingleLineElipseTextView;

/**
 * Created by lforxeverc on 2017/4/14.
 */

public class ArticleHolder extends BaseHolder<ArticleViewData> {
    private TextView tvTitle;
    private SingleLineElipseTextView tvShareInfo;
    private FrescoImageView ivCover;
    private RelativeLayout rlShare;

    public ArticleHolder(View v, Context context, int type) {
        super(v, context, type);
    }

    @Override
    protected void initView() {
        tvTitle = (TextView) itemView.findViewById(R.id.tv_title);
        tvShareInfo = (SingleLineElipseTextView) itemView.findViewById(R.id.tv_share_msg);
        rlShare = (RelativeLayout) itemView.findViewById(R.id.rl_share);
        ivCover = (FrescoImageView) itemView.findViewById(R.id.iv_cover);
        tvShareInfo.setTextSize(11);
    }

    @Override
    public void setViews(final int position, final ArticleViewData data, final IActionListener mListener) {
        tvTitle.setTextColor(ContextCompat.getColor(getContext(), data.isHasRead() ? R.color.listItem_flag_color : R.color.text_black));
        tvTitle.setText(data.getTitle());
        ShareInfo shareInfo = data.getShareInfo();
        if (shareInfo != null && shareInfo.getShareTime() != 0) {
            String name = shareInfo.getUserName();
            tvShareInfo.setText(DateUtils.dealWithDateInArticle(getContext(), shareInfo.getShareTime()), name);
        } else {
            tvShareInfo.setText(DateUtils.dealWithDateInArticle(getContext(), data.getCreateTime()), null);
        }
        ivCover.loadView(data.getCoverUrl());
    }
}
